# -*- coding:utf-8
"""
作者: Jia
日期: 2022年04月17日
描述: https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/
"""


class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        ans = 0
        c_dict = dict()
        left = -1
        for i, c in enumerate(s):
            if c in c_dict and c_dict[c] > left:
                left = c_dict[c]
                c_dict[c] = i
            else:
                ans = max(ans, i - left)
                c_dict[c] = i
        return ans
